home *** CD-ROM | disk | FTP | other *** search
/ boe.pres.k12.wv.us / boe.pres.k12.wv.us.zip / boe.pres.k12.wv.us / Utilities / Xerox Workcentre 5335 / Windows Scan / 32-bit_x86 / Francais / cpsimage.cab / data / docio / fileio.elf < prev    next >
Text File  |  2009-03-16  |  2KB  |  75 lines

  1. /*
  2. ** $Id: fileio.elf,v 1.4 2008/02/13 16:01:13 campanel Exp $
  3. **
  4. ** Class for Text File IO
  5.  
  6. **
  7. *******************************************************************************/
  8. #load "sys/stdlib.elf"; 
  9.  
  10. /******************************************************************************/
  11. /* @FILEIO */
  12. /* @New This class is used for Input / Output with text files ??? what's unique about this?
  13. */
  14. /* @initialize Causes the controller environment to be initialized. */
  15. /******************************************************************************/
  16. CLASS FILEIO {
  17.     METHOD New () { }
  18.  
  19.     METHOD initialize (STRING filename, STRING iomode)
  20.     {
  21.         if (this.isInitialized == FALSE) {
  22.             this.filename = filename;
  23.             if (iomode.strcasecmp(str:"r") == TRUE)
  24.             {
  25.                 this.isReader = TRUE;
  26.                 this.fileContent = ReadObject(filename:filename, override: TRUE);
  27.             }
  28.             else if (iomode.strcasecmp(str:"w") == TRUE)
  29.             {
  30.                 FILE file = new(FILE, path:filename);
  31.                 if (file.exists() == TRUE)
  32.                     file.deleteFile();
  33.                 this.isReader = FALSE;
  34.                 
  35.             }
  36.             else if (iomode.strcasecmp(str:"a") == TRUE)
  37.             {
  38.                 this.isReader = FALSE;
  39.             }
  40.             this.isInitialized = TRUE;
  41.         }
  42.     }
  43.  
  44.     METHOD getLine() RETURNS (STRING line)
  45.     {
  46.         if (this.isReader == TRUE)
  47.             line = this.fileContent.getLine();
  48.     }
  49.  
  50.     METHOD putline(STRING line)
  51.     {
  52.         if (this.isReader == FALSE)
  53.         {
  54.             INTEGER ind = line.length()-1;
  55.             STRING lastChar = line.index( val:ind );
  56.             line.Write (filename: this.filename, value: TRUE, mode: "a");
  57.             if (lastChar.strcasecmp(str: this.lnfeed) == FALSE)
  58.                 this.lnfeed.Write (filename: this.filename, value: TRUE, mode: "a");
  59.         }
  60.     }
  61.  
  62.     METHOD rewind()
  63.     {
  64.         if (this.isReader == TRUE)
  65.             this.fileContent.resetToken();
  66.     }
  67.  
  68.     /* Internal Data Members */
  69.     STRING filename;
  70.     BOOLEAN isInitialized = FALSE;
  71.     BOOLEAN isReader = FALSE;
  72.     STRING fileContent;
  73.     STRING lnfeed = "\n";
  74. }
  75.